<?php
	class GP_sqlobjet
	{
		var $_db;
		var $_sql;
		var $_count = 0;
		var $_res = array();
		
		static $_instance;
		
		// singleton
		public function &getInstance($sql) 
		{
			if (!self::$_instance instanceof self)
				self::$_instance = new self($sql);
			return self::$_instance;
		}
		
		function __construct($sql)
		{
			$this -> _db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
			$this -> _sql = $sql;
		}
		
		function get($condition = '')
		{
			if (strlen($condition) > 0)
				$sql = $this -> _sql . ' WHERE ' . $condition;
			else
				$sql = $this -> _sql;
			$this -> _res = $this -> _db -> fetchArray($sql);
			$this -> _count = count($this -> _res);
		}
		
		function objet($ligne)
		{
			foreach ($ligne as $champ => $valeur)
				$this -> $champ = $valeur;
		}
	}
?>